package com.ajouroid.smartcoworker;

import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService {

	String TAG = "GCMIntentService";
	final static String SENDER_ID = "1016502050851";

	public GCMIntentService()
	{
		super(SENDER_ID);
	}
	
	
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return super.onBind(intent);
	}
	
	@Override
	protected void onError(Context arg0, String arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onMessage(Context arg0, Intent arg1) {
		if (arg1.hasExtra("type") && arg1.hasExtra("content"))
		{
			String type = arg1.getStringExtra("type");
			String content = arg1.getStringExtra("content");
			Log.d(TAG, "[" + type + "] Push Message Received\n" + content);
			
			Intent i = new Intent("edu.ajou.smartcoworker.PUSHMSG");
			i.putExtra("type", type);
			i.putExtra("content", content);
			
			arg0.sendBroadcast(i);			
		}
	}

	final String ONREGISTER = "com.ajouroid.smartcoworker.ON_REGISTERED";
	
	@Override
	protected void onRegistered(Context arg0, String arg1) {
		Log.d(TAG,arg1);
		
		Intent i = new Intent(ONREGISTER);
		i.putExtra("regId", arg1);
		arg0.sendBroadcast(i);
	}

	@Override
	protected void onUnregistered(Context arg0, String arg1) {
		// TODO Auto-generated method stub
		
	}
}
